/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PM;

import csse3004.GD.Account;
import csse3004.GD.DA.WBUserDA;
import csse3004.GD.WBUser.PollUsers;
import csse3004.GD.WBUser.WBUserService;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Lan YE 42239015
 */
public class ActiveuserController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());
    private WBUserService service = new WBUserDA();

    /**
     *This function is for getting the all the users in a poll
     *
     **/
    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) {
        
        ArrayList<PollUsers> userlist = new ArrayList<PollUsers>();
        try {            
            //odd workaround. Don't judge me!
            String temp = (String)hsr.getParameter("pollID");
            int pollID = Integer.parseInt((String) temp);
            userlist = (service.database)?service.getActiveUsers(pollID):new PollUsers().genTestUsers();
            return new ModelAndView("viewactiveuser", "users", userlist);
        } catch (Exception e) {
            System.err.println("There was an error. Reason:");
            System.err.println(e);
        }
        return new ModelAndView("viewactiveuser");

    }
}
